package com.yoomiito.app.ui.video.clip

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseActPresenter
import com.yoomiito.app.model.BaseList
import com.yoomiito.app.model.home.VideoClipInfo
import com.yoomiito.app.model.video.VideoOtherInfo
import com.yoomiito.app.net.YmApi

class VideoClipListPresenter(appConfig: AppConfig) :BaseActPresenter<VideoClipListActivity>(appConfig){

    fun getVideoList(page:Int,size:Int){
        YmApi.getYmService()
                .videoClipList(page,size)
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object :ApiSubscriber<BaseList<VideoClipInfo>>(handleException()){
                    override fun onSuccess(t: BaseList<VideoClipInfo>?) {
                        v.setDatas(t)
                    }

                    override fun onFail(error: ApiException?) {
                        v.dismissLoading()
                    }
                })
    }

    fun getVideoDetail(id:String){
        YmApi.getYmService()
                .videoDetail(id)
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object :ApiSubscriber<VideoOtherInfo>(){
                    override fun onSuccess(t: VideoOtherInfo?) {
                        v.setVideoInfo(t)
                    }

                    override fun onFail(error: ApiException?) {

                    }
                })
    }
}